home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / VideoToolboxSources / ReadLuminanceRecord.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-17  |  6.5 KB  |  185 lines  |  [TEXT/KAHL]

  1. /*
  2. ReadLuminanceRecord.c
  3.  
  4. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags);
  5.  
  6.     i=ReadLuminanceRecord("LuminanceRecord1.h",&LR,0);
  7. Reads a LuminanceRecord?.h file at runtime. In the past, these calibration-data files
  8. could only be used by #including them at compile time.
  9.  
  10.     long WriteLuminanceRecord(char *filename,LuminanceRecord *LP,short flags);
  11. Writes (and verifies) a LuminanceRecord, appending to the file.
  12.  
  13.     Description *DescribeLuminanceRecord(LuminanceRecord *LP);
  14. Creates a Description array to read and write LuminanceRecord assignment files.
  15.  
  16.  
  17. HISTORY:
  18. 7/29/91 dgp
  19. 8/24/91    dgp    Made compatible with THINK C 5.0.
  20.             Preserve default values of LP->VMin and LP->VMax if no new values are read.
  21. 8/26/91    dgp    Rewrote using new SetVariable() routine, which makes the code easier to
  22.             read. 
  23. 12/17/92 dgp Added dacSize.
  24. 12/21/92 dgp Changed type of dacSize from long to short.
  25. 6/3/93    dgp    Updated to work with new Assign.c. 
  26.             Created DescribeLuminanceRecordAssignment() and WriteLuminanceRecord().
  27. 8/12/93    dgp    Renamed routines to be consistent with new Assign.c.
  28.             Renamed "DescribeLuminanceRecordAssignment" to "DescribeLuminanceRecord".
  29. 3/4/94    dgp ReadLuminanceRecord no longer initializes. Added InitializeLuminanceRecord.
  30. */
  31.  
  32. #include "VideoToolbox.h"
  33. #include "Luminance.h"
  34. #include <assert.h>
  35. #define VARIABLES 32
  36. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags);
  37.  
  38. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags)
  39. {
  40.     Description *d;
  41.     long n;
  42.  
  43.     d=DescribeLuminanceRecord(LP);
  44.     if(d==NULL){
  45.         if(flags&assignNoPrintfExit)return assignMemoryError;
  46.         else PrintfExit("\InitializeLuminanceRecord: no room for Variables.\n\007");
  47.     }
  48.     n=InitializeDescribedVars(d,flags);
  49.     LP->dacSize=8;                    /*  default value */
  50.     free(d);
  51.     return n;
  52. }
  53.  
  54. long ReadLuminanceRecord(char *filename,LuminanceRecord *LP,short flags)
  55. {
  56.     Description *d;
  57.     long n;
  58.  
  59.     d=DescribeLuminanceRecord(LP);
  60.     if(d==NULL){
  61.         if(flags&assignNoPrintfExit)return assignMemoryError;
  62.         else PrintfExit("\nReadLuminanceRecord: no room for Variables.\n\007");
  63.     }
  64. //    n=InitializeDescribedVars(d,flags);
  65.     LP->dacSize=8;                    /*  default value */
  66.     n=ReadAssignmentFile(filename,d,flags);
  67.     free(d);
  68.     return n;
  69. }
  70.  
  71. long WriteLuminanceRecord(char *filename,LuminanceRecord *LP,short flags)
  72. {
  73.     Description *d=NULL,*d2=NULL;
  74.     LuminanceRecord *LP2=NULL;
  75.     long n,m;
  76.  
  77.     /*  Write */
  78.     d=DescribeLuminanceRecord(LP);
  79.     if(d==NULL){
  80.         n=assignMemoryError;
  81.         if(flags&assignNoPrintfExit)goto done;
  82.         else PrintfExit("\nWriteLuminanceRecord: no room for Variables.\n\007");
  83.     }
  84.     n=PrintAssignmentsToFile(filename,d,flags);
  85.     SetFileInfo(filename,'TEXT','KAHL');
  86.     if(n<0)goto done;
  87.     
  88.     /*  Verify */
  89.     LP2=(LuminanceRecord *)malloc(sizeof(LuminanceRecord));
  90.     if(LP2==NULL){
  91.         n=assignMemoryError;
  92.         if(flags&assignNoPrintfExit)goto done;
  93.         else PrintfExit("\nWriteLuminanceRecord: no room for LuminanceRecord.\n\007");
  94.     }
  95.     d2=DescribeLuminanceRecord(LP2);
  96.     if(d2==NULL){
  97.         n=assignMemoryError;
  98.         if(flags&assignNoPrintfExit)goto done;
  99.         else PrintfExit("\nWriteLuminanceRecord: no room for Variables.\n\007");
  100.     }
  101.     m=ReadAssignmentFile(filename,d2,flags|assignReportUnknown);
  102.     if(m<0){
  103.         n=m;
  104.         goto done;
  105.     }
  106.     m=UnequalDescribedVars(d,d2,flags);
  107.     if(m<0){
  108.         n=m;
  109.         goto done;
  110.     }
  111. done:
  112.     if(d2!=NULL)free(d2);
  113.     if(LP2!=NULL)free(LP2);
  114.     if(d!=NULL)free(d);
  115.     return n;
  116. }
  117.  
  118. Description *DescribeLuminanceRecord(LuminanceRecord *LP)
  119. {
  120.     Description *d;
  121.     int j;
  122.  
  123.     d=(Description *)malloc(VARIABLES*sizeof(Description));
  124.     if(d==NULL)return NULL;
  125.     j=0;
  126.     d[j++]=Describe(shortType,&LP->screen,"LR.screen"
  127.         ,"device=GetScreenDevice(LR.screen);");
  128.     d[j++]=Describe(stringType,&LP->id,"LR.id",NULL);
  129.     d[j++]=Describe(stringType,&LP->name,"LR.name",NULL);
  130.     d[j++]=Describe(stringType,&LP->date,"LR.date",NULL);
  131.     d[j++]=Describe(stringType,&LP->notes,"LR.notes",NULL);
  132.     d[j++]=Describe(shortType,&LP->dacSize,"LR.dacSize",NULL);
  133.     d[j++]=Describe(doubleType,&LP->LMin,"LR.LMin","luminance at VMin");
  134.     d[j++]=Describe(doubleType,&LP->LMax,"LR.LMax"
  135.         ,"luminance at VMax");
  136.     d[j++]=Describe(doubleType,&LP->LBackground,"LR.LBackground"
  137.         ,"background luminance during calibration");
  138.     d[j++]=Describe(shortType,&LP->VBackground,"LR.VBackground"
  139.         ,"background number used during calibration");
  140.     d[j++]=Describe(doubleType,&LP->dpi,"LR.dpi","pixels/inch");
  141.     d[j++]=Describe(doubleType,&LP->Hz,"LR.Hz","frames/second");
  142.     d[j++]=Describe(stringType,&LP->units,"LR.units",NULL);
  143.     d[j++]=Describe(longType,&LP->coefficients,"LR.coefficients"
  144.         ,"# of coefficients in polynomial fit");
  145.     d[j++]=DescribeArray(doubleType,&LP->p,"LR.p"
  146.         ,"L(V)=p[0]+p[1]*V+p[2]*V*V+ . . . ±polynomialError"
  147.         ,sizeof(LP->p)/sizeof(LP->p[0]),0L);
  148.     d[j++]=Describe(doubleType,&LP->polynomialError,"LR.polynomialError"
  149.         ,"RMS error of fit");
  150.     d[j++]=DescribeArray(doubleType,&LP->q,"LR.q"
  151.         ,"L(V)=q[0]+q[1]*V+q[2]*V*V±quadraticError",sizeof(LP->q)/sizeof(LP->q[0]),0L);
  152.     d[j++]=Describe(doubleType,&LP->quadraticError,"LR.quadraticError"
  153.         ,"RMS error of fit");
  154.     d[j++]=DescribeArray(doubleType,&LP->power,"LR.power"
  155.         ,"L(V)=power[0]+Rectify(power[1]+power[2]*V)^power[3]±powerError */\\\n"
  156.         "    /* where Rectify(x)=x if x≥0, and Rectify(x)=0 otherwise. */\\\n"
  157.         "    /* Pelli & Zhang (1991) Eqs.9&10 use symbols v=V/255, */\\\n"
  158.         "    /* alpha=power[0], beta=power[1], kappa=power[2]*255, gamma=power[3]"
  159.         ,sizeof(LP->power)/sizeof(LP->power[0]),0L);
  160.     d[j++]=Describe(doubleType,&LP->powerError,"LR.powerError"
  161.         ,"RMS error of fit");
  162.     d[j++]=DescribeArray(doubleType,&LP->fixedPower,"LR.fixedPower"
  163.         ,"L(V)=fixedPower[0]+Rectify(fixedPower[1]+fixedPower[2]*V)^fixedPower[3]±fixedPowerError */\\\n"
  164.         "    /* The exponent fixedPower[3] is fixed."
  165.         ,sizeof(LP->fixedPower)/sizeof(LP->fixedPower[0]),0L);
  166.     d[j++]=Describe(doubleType,&LP->fixedPowerError,"LR.fixedPowerError"
  167.         ,"RMS error of fit");
  168.     d[j++]=Describe(doubleType,&LP->r,"LR.r",NULL);
  169.     d[j++]=Describe(doubleType,&LP->g,"LR.g",NULL);
  170.     d[j++]=Describe(doubleType,&LP->b,"LR.b",NULL);
  171.     d[j++]=Describe(doubleType,&LP->gainAccuracy,"LR.gainAccuracy",NULL);
  172.     d[j++]=Describe(doubleType,&LP->gm,"LR.gm"
  173.         ,"The monitor's contrast gain.");
  174.     d[j++]=Describe(shortType,&LP->rangeSet,"LR.rangeSet"
  175.         ,"zero indicates that range parameters have yet to be set");
  176.     d[j++]=Describe(shortType,&LP->L.exists,"LR.L.exists"
  177.         ,"zero indicates that luminance table has yet to be initialized");
  178.     d[j++]=Describe(shortType,&LP->VMin,"LR.VMin"
  179.         ,"minimum value that can be loaded into DAC");
  180.     d[j++]=Describe(shortType,&LP->VMax,"LR.VMax"
  181.         ,"maximum value that can be loaded into DAC");
  182.     d[j++]=Describe(0,NULL,NULL,NULL);                /* Mark end of list */
  183.     assert(j<=VARIABLES);
  184.     return d;
  185. }